#define TRACE
#include <System.cpu\cpuFalloc.h>

#include <stdio.h>

void testFalloc(fallocHeap* heap)
{
	fallocInit(heap);

	// create/free heap
	void* obj = fallocGetChunk(heap);
	fallocFreeChunk(heap, obj);
/*
	void* obj2 = fallocGetChunks(heap, 144*2);
	fallocFreeChunks(heap, obj2);
*/	

	// create/free alloc
	fallocContext* ctx = fallocCreateCtx(heap);
	char* testString = (char*)falloc(ctx, 10);
	int* testInteger = falloc<int>(ctx);
	fallocDisposeCtx(ctx);

	// create/free stack
	fallocContext* stack = fallocCreateCtx(heap);
	fallocPush<int>(ctx, 1);
	fallocPush<int>(ctx, 2);
	int b = fallocPop<int>(ctx);
	int a = fallocPop<int>(ctx);
	fallocDisposeCtx(ctx);
}

void main()
{
	cpuFallocHost fallocHost = cpuFallocWTraceInit(2048);

	testFalloc(fallocHost.heap);

	// trace
	cpuFallocTrace* trace = cpuFallocTraceInit();
	void* buffer; size_t length;
	while (buffer = cpuFallocTraceStream(fallocHost, trace, length)) {
		printf("z: %d\n", length);
	}
	cpuFallocTraceEnd(trace);

	// free and exit
	cpuFallocWTraceEnd(fallocHost);
	printf("done."); char c; scanf_s("%c", &c);
}
